/****** Object:  StoredProcedure [dbo].[sp_KCL_CreateNewUser]    Script Date: 04/21/2011 22:43:58 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_KCL_CreateNewUser]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_KCL_CreateNewUser]
GO

/****** Object:  StoredProcedure [dbo].[sp_KCL_CreateNewUser]    Script Date: 04/21/2011 22:43:58 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- ==================================================================================
-- Revision History:
-- Date					Author			Description
-- 21-04-2011			btnam			Create script
-- ==================================================================================
CREATE PROCEDURE [dbo].[sp_KCL_CreateNewUser]

	@UserName		NVARCHAR(100),
    @PassWord		NVARCHAR(100),
    @FullName		NVARCHAR(100),
    @Code			NVARCHAR(100),
    @Email			NVARCHAR(100),
    @isAdmin		BIT,
    @canCreate		BIT,
    @canModify		BIT,
    @canRead		BIT,
    @isActive		BIT,
    @ID				INT OUTPUT
    
AS
BEGIN
	
	SET NOCOUNT ON;
	
	IF NOT EXISTS (
					SELECT [username],[email]
					FROM [User]
					WHERE [username] = @UserName
						  OR [email] = @Email
				  )
	BEGIN					
	
					INSERT INTO	[dbo].[User](
												[username],[password],[fullname],[email],[code]
												,[admin],[create],[edit],[read],[isActive]
												
											)
					VALUES					(
												@UserName,@PassWord,@FullName,@Email,@Code
												,@isAdmin,@canCreate,@canModify,@canRead,@isActive
											)	
					SET @ID = @@IDENTITY	
	
	END					
	ELSE			SET @ID = -1;
    
END

GO


